var datatable_config = {
	bJQueryUI: false, bFilter: true,bSort:true,aaSorting:[[0,"desc"]],bLengthChange: false,iDisplayLength:20,
	oLanguage: {sUrl: "js/libs/jquery.datatables/zh.txt" }
};
jQuery(document).ready(function ($) {
	$(".yncheckbox").live('click',function(){
		$(this).next().val($(this).prop( "checked" )?"1":"0");
	});
	madmin.init();

	// make code pretty
	window.prettyPrint && prettyPrint();

	
	$('a.help-link').pageslide({
		direction: 'left'
	});
	
	$(".file-input").live("click",function(){
		var $THIS = $(this);
		$("#uploadForm").attr('target',$THIS.attr("name")).modal('show');
	});
	
	$("#uploadForm form .btn-primary[type='button']").live('click',function(){
		//加载动画
		var $form = $(this).parent();
		
		var $spinner = $form.find("#spinner-div");
		$spinner.fadeIn();
		$form.ajaxSubmit({dataType:"html",success:function(data){
			data = $.parseJSON(data);
			debug(data);
			if(data.code==0){
				var name = $("#uploadForm").attr("target");
				if(name){
					$(".file-input[name='"+name+"']").val(data.title);
					$("#"+name+"-guid").val(data.guid);
					$("#"+name+"-ext").val(data.ext);
				}
			}else{
				bootbox.alert(data.msg);
			}
			//关闭动画和窗口
			$spinner.fadeOut();
			$("#uploadForm").modal("hide");
		}
		});
		
	});
	$("#uploadForm form .btn-danger").live("click",function(){
		$("#uploadForm").modal("hide");
	});

	//初始化 slider的菜单，用来 ajax请求内容
	$("#CHART-NAV").slider({'target':'#TPL'});
	$("#USER-NAV").slider({'target':'#TPL'});
	$("#MATTER-NAV").slider({'target':'#TPL'});
	$("#SETTING-NAV").slider({'target':'#TPL'});
	$("#WORKFLOW-NAV").slider({'target':'#TPL'});
	$("#PROFILE-NAV").slider({'target':'#TPL',selector:"a[data-target-page]"});
	$.reflect({'targets':".reflect"});
	//$(".toolbar").toolbar();
	
	$(".btn-ajax-back").live('click',function(){
		$("#FORM-DIALOG").modal('hide');
	});
	
	/*
	$(".btn-ajax-save").live('click',function(){
		var $form = $(this).parents("form");
		var fields = $form.formToArray();
		fields = $.arrayToObj(fields);
		$THIS = $(this);
		var isajax = true;
		
		if("0" == $THIS.attr("isajax")) isajax = false;
		if(!isajax){
			$form.ajaxSubmit({dataType:"html",success:function(html){
				$("#FORM-DIALOG").modal('hide');
					$("#TPL .tpl-title").text(' ');
					$("#TPL .content").html(html);
				}
			});
			return false;
		}
		$form.ajaxSubmit({dataType:"json",success:function(data){
			if(data.code==0){
				var o = $THIS.attr('o');
				if('add'==o){
					var row = [];
					$(".datatable th[col]").each(function(){
						row[row.length] = fields[$(this).attr('col')];
					});
					//添加按钮
					
					row[row.length] = '<button class="btn btn-small btn-primary edit" href="/OA/c?s=tpl&amp;o=form&amp;p=edit&amp;m_id=66&amp;pri=ds_id&amp;v=sys_ds&amp;key=34"><i class="icon-pencil"></i></button> '+
					'<button class="btn btn-small btn-danger delete" href="/OA/c?s=tpl&amp;o=delete&amp;isajax=1&amp;m_id=66&amp;pri=ds_id&amp;v=sys_ds&amp;key=34"><i class="icon-remove"></i></button>';
					debug(row);
					$(".datatable").dataTable().fnAddData(row);
					
				}else{
					
				}
				bootbox.alert("<p><i class='icon-ok'></i> 操作成功!</p>");
				//$form.resetForm();
				$("#FORM-DIALOG").modal('hide');
			}else{
				bootbox.alert("<p><i class='icon-remove'></i> "+data.msg+"</p>");
			}
		}});
		return false;
	});
	//*/
	
	
});
